<?
    /**
     * PrincipioLab
     *
     * @package    PrincipioLab
     */

    /**
     * PrincipioLab_LinkedList_ListElementIterator
     *
     * @package    PrincipioLab\LinkedList
     */
    class PrincipioLab_LinkedList_ListElementIterator implements Iterator
    {
        /** @var PrincipioLab_LinkedList */
        private $linked_list;

        /** @var null|PrincipioLab_ListElement */
        private $list_element;


        public function __construct(PrincipioLab_LinkedList $linked_list)
        {
            $this->linked_list = $linked_list;
            $this->list_element = $linked_list->getRootItem();
        }


        /**
         * @return void
         */
        public function rewind()
        {
            $this->list_element = $this->linked_list->getRootItem();
        }


        /**
         * @return null|PrincipioLab_ListElement
         */
        public function current()
        {
            return $this->list_element;
        }


        /**
         * @return mixed
         */
        public function key()
        {
            return $this->list_element->_getID();
        }


        /**
         * return null|PrincipioLab_ListElement
         */
        public function next()
        {
            $this->list_element = $this->list_element->getNext();
        }


        /**
         * @return bool
         */
        public function valid()
        {
            return (!is_null($this->list_element));
        }
    }
?>